package com.clay.algorithm;

/**
 * @Author : clay
 * @Description:
 * @Date: Create in 21:21 2021/3/20
 * @Modified By:
 */
public class test05 {
    public static void main(String[] args) {
        String s="we are happy";
        Solution05 solution = new Solution05();
        String s1 = solution.replaceSpace(s);
        System.out.println(s1);
    }
}
//class Solution05 {
//    public String replaceSpace(String s) {
//        char[] chars = s.toCharArray();
//        String k="";
//        int i=0;
////        for (int j=0;j<chars.length;j++)
////        {
////            System.out.println( i+" :"+chars[j]);
////        }
//        while (i<chars.length)
//        {
//            if(chars[i]==' ')
//            {
//                k+="%20";
//            }
//            else {
//                k+=(chars[i]+"");
//            }
//            i++;
//        }
//        return k;
//    }
//}


class Solution05 {
    public String replaceSpace(String s) {
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i <s.length() ; i++) {
            char a=s.charAt(i);
            if(a==' ')
            {
                stringBuilder.append("%20");
            }
            else {
                stringBuilder.append(a);
            }
        }


        return stringBuilder.toString();
    }
}
